﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _028接口_依赖反转_单元测试3_单元测试
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var deskFan = new DeskFan(new PowerSupply());
            Console.WriteLine(deskFan.Work());
        }
    }

    public  interface IPowerSupply
    {
        int GetPower();
    }

     //单元测试  相当于中间件操作 否则会直接影响其他层(例如后端开发中的控制器数据库操作)
    public class PowerSupply:IPowerSupply
    {
        public int GetPower()
        {
            return 100;
        }
    }

    public  class DeskFan
    {
        private IPowerSupply  _powerSupply;
        public DeskFan(IPowerSupply powerSupply)
        {
            this._powerSupply = powerSupply;
        }

        public string Work()
        {
            int power = _powerSupply.GetPower();
            if (power < 0)
            {
                return "wont't work";
            }
            else if (power < 100)
            {
                return "slow";
            }
            else if (power < 200)
            {
                return "Work fine";
            }
            else
            {
                return "Explode!";
            }
        }
    }
}
